
void _info( char* str){
  Serial.println(str);
}

void showHeap(){
  long  fh = ESP.getFreeHeap();
  char  fhc[20];

  ltoa(fh, fhc, 10);
  String freeHeap = String(fhc);
  Serial.println("freeHeap: " + freeHeap);
}



bool getLocalTime(struct tm * info, uint32_t ms) {
  uint32_t count = ms / 10;
  time_t now;

  time(&now);
  localtime_r(&now, info);

  if (info->tm_year > (2016 - 1900)) {
    return true;
  }

  while (count--) {
    delay(10);
    time(&now);
    localtime_r(&now, info);
    if (info->tm_year > (2016 - 1900)) {
      return true;
    }
  }
  return false;
}

String localTime(bool escape){
  struct tm tmstruct;
    if(!getLocalTime(&tmstruct, 1000)){
    Serial.println("Failed to obtain time");
    return "";
  }
  
//  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
    Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
  char ret[50]; 
  //sprintf(ret, "%d-%02d-%02d %02d:%02d:%02d", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);

  if(escape){
      sprintf(ret, "%d-%02d-%02d%%20%02d%%3A%02d%%3A%02d", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
  }else{
      sprintf(ret, "%d-%02d-%02d %02d:%02d:%02d", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
  }
  return ret;
  // asctime(&tmstruct);  
}



String getVoltage(int pin)
{   
  float volts = ESP.getVcc();
  
  Serial.printf("The internal VCC reads %1.2f volts\n", volts / 1000);
  
  String voltage = "getVoltage: " + String(  volts / 1000 );
  Serial.println(voltage);
  
//    Serial.println("getVoltage: "+ String(pin) );
//    uint16_t v = analogRead(pin | ADC_PIN);
//    float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0);
//    String voltage = "Voltage :" + String(battery_voltage) + "V";
//    Serial.println(voltage);
    return voltage;     
}